/*****************************************************************************/
/*                                                                           */
/*    Domino Operation System Kernel Module                                  */
/*                                                                           */
/*    Copyright (C) 2005 Laszlo Arvai                                        */
/*                                                                           */
/*    ------------------------------------------------------------------     */
/*    drvRealTimeClock - Real Time Clock Driver Module                       */
/*****************************************************************************/

///////////////////////////////////////////////////////////////////////////////
// Includes
#include <windows.h>
#include "krnlMessageQueue.h"
#include "drvRealTimeClock.h"
#include "krnlRealTimeClock.h"
#include "sysSettings.h"

///////////////////////////////////////////////////////////////////////////////
// Module variables

//////////////////////////////////////////////////////////////////////////////
// Send real time clock message
void krnlSendRealTimeClockMessage(void)
{
#ifdef msgREAL_TIME_MESSAGE
  SYSTEMTIME time;
  krnlMessage* message;

  GetLocalTime( &time );

  // send message
  message = krnlAllocateAsyncMessage();
  if( message != NULL )
  {
    message->Id = msgREAL_TIME_MESSAGE;

    // time
    message->Data[0] = (dosByte)time.wHour;
    message->Data[1] = (dosByte)time.wMinute;
    message->Data[2] = (dosByte)time.wSecond;

    // date
    message->Data[3] = time.wYear & 0xff;
    message->Data[4] = time.wYear >> 8;
    message->Data[5] = (dosByte)time.wMonth;
    message->Data[6] = (dosByte)time.wDay;

    //  day of week
    message->Data[7] = (dosByte)time.wDayOfWeek;
  }
#endif
}

///////////////////////////////////////////////////////////////////////////////
// Init real time clock
void drvInitRealTimeClock(void)
{
  krnlSendRealTimeClockMessage();
}

///////////////////////////////////////////////////////////////////////////////
// Gets Date & Time
void krnlGetDateTime( dosDateTime* in_datetime )
{
  SYSTEMTIME time;

  GetLocalTime( &time );

  // time
  in_datetime->Hour   = (dosByte)time.wHour;
  in_datetime->Minute = (dosByte)time.wMinute;
  in_datetime->Second = (dosByte)time.wSecond;

  // date
  in_datetime->Year   = (dosWord)time.wYear;
  in_datetime->Month  = (dosByte)time.wMonth;
  in_datetime->Day    = (dosByte)time.wDay;

  //  day of week
	krnlUpdateDayOfWeek( in_datetime );
}

///////////////////////////////////////////////////////////////////////////////
// Sets Date & Time
void krnlSetDateTime(dosDateTime* in_datetime)
{
	// empty
}
